package com.tangfuzhong.service;

import org.springframework.context.SmartLifecycle;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

/**
 * 当Spring容器完成初始化后，会接着回调实现SmartLifecycle接口的类中对应的start()方法
 * 例子：EurekaServerInitializerConfiguration，TangMessageSmartLifecycle
 */

@Configuration
public class TangMessageSmartLifecycle implements SmartLifecycle, Ordered {
    @Override
    public boolean isAutoStartup() {
        System.out.println("MessageSmartLifecycle isAutoStartup");
        //return false;
        return true;
    }

    @Override
    public void stop(Runnable callback) {

    }

    @Override
    public void start() {
        System.out.println("MessageSmartLifecycle start");
    }

    @Override
    public void stop() {
        System.out.println("MessageSmartLifecycle stop");
    }

    @Override
    public boolean isRunning() {
        System.out.println("MessageSmartLifecycle isRunning");
        return false;
        //return true;
    }

    @Override
    public int getPhase() {
        return 0;
    }

    @Override
    public int getOrder() {
        return 1;
    }
}
